#ifndef USER_TASK_H
#define USER_TASK_H

/* Includes ----------------------------------------------------------------- */

#include <cmsis_os2.h>

#include "freertos_mpool.h" 
#include "FreeRTOS.h"
#include "task.h"

#include  "config.h"
/* Exported constants ------------------------------------------------------- */

/* 扢�有任务都要define丢�个��任务运行频率��和“初始化延时 1�7 */
//分配的频率该如何给定＄1�7

#define TASK_FREQ_CHASSIS (500u)
#define TASK_FREQ_CTRL_CMD (500u)
#define TASK_FREQ_NUC (250u)
#define TASK_FREQ_CAN (1000u)
#define TASK_FREQ_ACTION (250u)
#define TASK_FREQ_NAVI (500u)
#define TASK_FREQ_R12DS (1000u)

#define DEBUG


#define TASK_INIT_DELAY_ACTION (400u)

#define TASK_INIT_DELAY_NUC (500u)

/* Exported defines --------------------------------------------------------- */
/* Exported macro ----------------------------------------------------------- */
/* Exported types ----------------------------------------------------------- */

typedef struct {
  /* 任务 */
  struct {
    osThreadId_t atti_esti;
//		osThreadId_t buz;	
//		osThreadId_t chassis;
//		osThreadId_t navi;
//    osThreadId_t r12ds; 
//    osThreadId_t ai;
//    osThreadId_t can;
//    osThreadId_t action;
//		osThreadId_t cmd;
//    osThreadId_t nuc;
  } thread;

	/* 队列 */
  struct {
    struct {
      osMessageQueueId_t accl;     /* IMU读取 */
      osMessageQueueId_t gyro;     /* IMU读取 */
      osMessageQueueId_t eulr; /* 姿��解算得到的欧拉规1�7 */
    } imu;	


//     /* 控制指令 */
//    struct {
//      struct {
//        osMessageQueueId_t rc;
//        osMessageQueueId_t ops_9pos;//此消息队列用来传输给导航任务码盘的位置
//        osMessageQueueId_t ops_9;
//        osMessageQueueId_t nuc;
//      } raw;

//      osMessageQueueId_t chassis;
//      osMessageQueueId_t status;
//    } cmd;

//        /* can任务放入、读取，电机或电容的输入输出 */
//    struct {
//      struct {
//        osMessageQueueId_t chassis6020;
//        osMessageQueueId_t chassis5065;
//      } output;
//      struct {
//        osMessageQueueId_t chassisfed6020;
//        osMessageQueueId_t chassisfed5065;
//      } feedback;
//    } can;
//  
//    
    
  } msgq;
	

	/*互斥釄1�7*/
	struct {
		SemaphoreHandle_t imu_eulr;
	} mutex;


  const ConfigParam_t *config; /* 机器人参敄1�7 */
  
	
#ifdef DEBUG
  struct {
//    UBaseType_t chassis;
//    UBaseType_t can;
    UBaseType_t atti_esti;
//    UBaseType_t rs12ds;
//    UBaseType_t action;
//    UBaseType_t cmd;
//    UBaseType_t nuc;
//		UBaseType_t navi;
  } stack_water_mark; /* stack使用 */

  struct {
//    float chassis;
//    float can;
    float atti_esti;
//    float ai;
//    float r12ds;
//    float action;
//    float cmd;
//    float nuc;
//		float navi;
  } freq; /* 任务运行频率 */

  struct {
//    float chassis;
//    float can;
    float atti_esti;
//    float ai;
//    float r12ds;
//		float action;
//    float cmd;
//    float nuc;
//		float navi;
  } last_up_time; /* 任务朢�近运行时闄1�7 */
#endif
} Task_Runtime_t;

extern Task_Runtime_t task_runtime;

extern const osThreadAttr_t attr_init;

extern const osThreadAttr_t attr_atti_esti;

//extern const osThreadAttr_t attr_chassis;

//extern const osThreadAttr_t attr_buzzer;

//extern const osThreadAttr_t attr_calculate;

//extern const osThreadAttr_t attr_r12ds;

//extern const osThreadAttr_t attr_can;

//extern const osThreadAttr_t attr_action;

//extern const osThreadAttr_t attr_cmd;

//extern const osThreadAttr_t attr_nuc;

//extern const osThreadAttr_t attr_navi;

/* Exported functions prototypes -------------------------------------------- */
void Task_Init(void *argument);

void Task_AttiEsti(void *argument);

//void Buzzer_task(void *argument);

//void Task_Chassis(void *argument);

//void Task_Calc(void *argument);

//void Task_r12ds(void *argument);

//void Task_can(void *argument);

//void Task_action(void *argument);

//void Task_cmd(void *argument);

//void Task_nuc(void *argument);

//void Task_Navi(void *argument);
#endif
